import 'package:XinXiZiXun/common/utils/utils.dart';
import 'package:XinXiZiXun/common/values/values.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

//输入TextField
class RoundedInputField extends StatelessWidget {
  final String leftImagename;
  final String hintText;
  final double width;
  final double height;
  final bool issecrectbool;
  final int maxLeght;
  final TextInputType keyBoardType;
  final ValueChanged<String> onChanged;

  const RoundedInputField(
      {Key key,
      this.leftImagename,
      this.hintText,
      this.width,
      this.height,
      this.issecrectbool,
      this.maxLeght,
      this.keyBoardType,
      this.onChanged})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return TextFieldContainer(
      width: width,
      height: height,
      child: TextField(
        obscureText: issecrectbool,
        onChanged: onChanged,
        decoration: InputDecoration(
          icon: Image.asset(leftImagename),
          hintText: hintText,
          border: InputBorder.none,
        ),
        keyboardType: keyBoardType,
        inputFormatters: <TextInputFormatter>[
          LengthLimitingTextInputFormatter(maxLeght)
        ],
      ),
    );
  }
}

///TextField外壳
class TextFieldContainer extends StatelessWidget {
  final Widget child;
  final double width;
  final double height;

  TextFieldContainer({Key key, this.child, this.width, this.height})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      // margin: EdgeInsets.only(left: duSetWidth(ktDefaultPadding)),
      padding: EdgeInsets.symmetric(
        horizontal: duSetWidth(ktDefaultPadding),
        // vertical: duSetWidth(0),
      ),
      width: width,
      height: height,
      decoration: BoxDecoration(
        color: AppColors.primaryBackgroundColor,
        borderRadius: BorderRadius.circular(height / 2.0),
      ),
      child: child,
    );
  }
}
